#include "VDisk.h"
#include "AccessGenerater.h"
#include "LRU_Stack.h"
#include "Simulate_System.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;
int main(int argc, char* argv[]){

// 	AccessGenerater test(1, 2, 4);
// 	LRU_Stack cache(1,1,10);
// 	std::vector<VDisk*> disk_array;
// 	for (int i=0; i<4; ++i) {
// 		VDisk* _disk = new VDisk;
// 		disk_array.push_back(_disk);
// 	}
// 
// 	VDisk* _disk = new VDisk;
// 
// 	for(int i=0; i<5000; i++){
// 		int block_add = test.getAccess();
// 		cout <<"Access \t"<<block_add<<"\t";
// 		int real_accress = cache.accessBlock(block_add,1);
// 		cout << "Disk Access:\t";
// 		if(real_accress == -1)
// 			cout << "None \t";
// 		else
// 			cout << real_accress <<"\t";
// 
// 		if(real_accress > 0)
// 		{
// 			int did = real_accress/1000;
// 			_disk->access();
// 		}
// 		_disk->update();
// 
// 		cout << "Power Coms.: " << _disk->power_comsumption <<"\n"; 
// 		system("cls");
// 	}
// 	i
// 	
	int number_disk;
	int prority_disk_number;
	std::cout << "The number of Disks: ";
	std::cin >> number_disk;
	std::cout <<"\n";
	std::cout << "The number of Priority Disks: ";
	std::cin >> prority_disk_number;
	std::cout <<"\n";
	


	std::ofstream out_file(argv[2]);
	int m_pype = atoi(argv[1]);
	std::cout << "System Type:\n 1.PA-LRU\n 2.LRU\n 3.PA-MRU\n 4.MRU\n";
	std::cin >> m_pype;
	std::cout <<"\n";
	Simulate_System sys(number_disk, prority_disk_number, m_pype);
	srand (time(NULL));
	
	int simulate_steps = 400;
	std::cout << "The steps of Simulation:";
	std::cin >> simulate_steps;
	std::cout <<"\n";
	//out_file << simulate_steps<<"\n";

	for (int i=0; i<simulate_steps; i++)
	{
		sys.update(out_file);
	}
	out_file.close();

	int saved_power = simulate_steps*number_disk-sys.power_total;
	std::cout << "Power saved: " << simulate_steps*number_disk-sys.power_total<<" (" <<float(saved_power)*100.0/(simulate_steps*number_disk) << "%)\n";
	system("pause");
}